package com.zhiwei.most.ext

import com.drake.brv.BindingAdapter
import com.drake.brv.utils.divider

/**
 * Create by zhiweizhu on 2022/3/11
 */
fun BindingAdapter.addMode(any: Any?, invalidateItemDecorations: Boolean = true){
    if (any == null) return
    models?.let {
        mutable.add(any)
        notifyItemChanged(mutable.size)
        if(invalidateItemDecorations){
            rv?.invalidateItemDecorations()
        }
    } ?: let {
        models = mutableListOf(any)
    }

}

/**
 * @param invalidateItemDecorations 解决在在Diver时 局部刷新导致item间隔没有重新计算
 */
fun BindingAdapter.addMode(index: Int, any: Any?, invalidateItemDecorations: Boolean = true){
    if (any == null || index < 0) return
    models?.let {
        mutable.add(index, any)
        notifyItemChanged(index)
        if(invalidateItemDecorations){
            rv?.invalidateItemDecorations()
        }
    } ?: let {
        models = mutableListOf(any)
    }
}

